const app = getApp();
Page({
  data: {
    infoMessage: {},
    imageSrc: 'https://tdesign.gtimg.com/mobile/demos/image1.jpeg',
  },
  onLoad: function() {
    const that = this;
    const eventChannel = this.getOpenerEventChannel();
    eventChannel.on('params', (res) => {
      const { id } = res;
      wx.request({
        url: 'https://xuexiwuapi.jomoit.com/visitor-api/system/data/' + id,
        method: 'GET', 
        header: {
          "Content-Type": "application/json",
          Authorization: 'Bearer ' + app.globalData.token
        },
        success: function(res) {
          const { data } = res;
          const infoMessage = data.data;
          that.setData({
            infoMessage
          })
        },
      })
    })
  },
  onApprove() {
    wx.request({
      url: 'https://xuexiwuapi.jomoit.com/visitor-api//system/data',
      method: 'PUT', 
      header: {
        "Content-Type": "application/json",
        Authorization: 'Bearer ' + app.globalData.token
      },
      data: {
        id: this.data.infoMessage.id,
        state: "1"
      },
      success: function(res) {
        
      },
    })
  },
  onReject() {
    wx.request({
      url: 'https://xuexiwuapi.jomoit.com/visitor-api//system/data',
      method: 'PUT', 
      header: {
        "Content-Type": "application/json",
        Authorization: 'Bearer ' + app.globalData.token
      },
      data: {
        id: this.data.infoMessage.id,
        state: "2"
      },
      success: function(res) {
        
      },
    })
  }
})